package com.example.cofeed.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.cofeed.R;
import com.example.cofeed.entity.Catalogs;
import com.example.cofeed.entity.City;

/**
 * Created by mqwang on 2017/9/26.
 */

public class MySubscriptionAdapter extends BaseQuickAdapter<Catalogs, BaseViewHolder> {

    public MySubscriptionAdapter() {
        super(R.layout.item_my_subscription_list);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final Catalogs item) {

        helper.setText(R.id.name_tv, item.title);
        if (item.isSelect){
            helper.getView(R.id.rec_lv).setVisibility(View.GONE);
        }else {
            helper.getView(R.id.rec_lv).setVisibility(View.VISIBLE);
        }

        helper.getView(R.id.renew_tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setSelect(item);
            }
        });

        SubscriptionCityListAdapter cityAdapter = new SubscriptionCityListAdapter();
        RecyclerView recLv = helper.getView(R.id.rec_lv);
        recLv.setLayoutManager(new LinearLayoutManager(mContext));
        recLv.setAdapter(cityAdapter);
        cityAdapter.setNewData(item.citys);

        cityAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                final City city = (City) adapter.getData().get(position);
                ((SubscriptionCityListAdapter) adapter).setSelect(city);

            }
        });
    }


    public void setSelect(Catalogs select){
        select.isSelect = !select.isSelect;
        notifyDataSetChanged();
    }

}
